#!/usr/bin/python
import math
import random

def getName():
    x = 1
    y = 2
    result = {"+": x+y,
              "-": x-y,
              "*": x*y}
    print(result.get("+"))


def while__():
    i = 1
    while i < 5:
        print(i)
        i += 1
    else:
        print("i已经>5")

def for__():
    sum = 0
    for x in range(3, 5):
        sum = sum + x
    print(sum)

def test_for():
    count = 1
    # else会在循环正常执行完执行，如果break是不会执行的
    while count < 10:
        print "*" + str(count)
        count += 1
        if count % 2 == 0:
            print count
            break
    else:
        print "exit"
    print "-"*20

    # foreach
    for i in range(3):
        print i
    else:
        print "for 执行完成"
    print "-"*20

    # 索引迭代
    foo = ['列表', "test", "可以是多种类型"]
    for i in range(len(foo)):
        print foo[i]
    else:
        pass
        print "占位语句"

def math():
    print "-"*20
    print dir(math)
    # 绝对值，带小数点
    print math.fabs(10)
    # 上取整
    print math.ceil(4.1)

    #随机数
    print random.random()
    print math.e
    print math.pi


if __name__ == '__main__':
    getName()
    while__()
    for__()